﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Bear.Library.WinApi
{
    public class WinApiHelper
    {
        [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
        public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

        [DllImport("user32")]
        public static extern int IsWindowVisible(IntPtr hwnd);

        [DllImport("user32.dll", EntryPoint = "GetActiveWindow")]
        public static extern IntPtr GetActiveWindow();

        [DllImport("user32.dll")]
        public static extern int IsWindow(IntPtr hwnd);

        [DllImport("shell32.dll")]
        public static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);

        [DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
        public static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll", EntryPoint = "FindWindowEx", CharSet = CharSet.Auto)]
        public extern static IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("user32.dll")]
        public static extern IntPtr GetWindowRect(IntPtr hWnd, ref Rect rect);

        [DllImport("user32")]
        public static extern bool GetClientRect(IntPtr hwnd, ref Rect rect);

        [DllImport("user32.dll", SetLastError = true)]
        public static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);

        [DllImport("user32.dll")]
        public static extern IntPtr GetMessageExtraInfo();

        [DllImport("user32.dll")]
        public static extern IntPtr GetForegroundWindow();

        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetDesktopWindow();

        [DllImport("user32.dll")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool BRePaint);


        [DllImportAttribute("gdi32.dll")]
        public static extern bool BitBlt(
             IntPtr hdcDest, // 目标 DC的句柄
             int nXDest,
           int nYDest,
           int nWidth,
           int nHeight,
           IntPtr hdcSrc,  // 源DC的句柄
             int nXSrc,
           int nYSrc,
           System.Int32 dwRop  // 光栅的处理数值
             );

        [DllImportAttribute("User32.dll")]
        public static extern IntPtr GetWindowDC(IntPtr hwnd);

        [DllImportAttribute("gdi32.dll")]
        public static extern IntPtr CreateCompatibleDC(IntPtr hdc);

        [DllImportAttribute("gdi32.dll")]
        public static extern IntPtr CreateCompatibleBitmap(
            IntPtr hdc,
            int nWidth,     // width of bitmap, in pixels
            int nHeight // height of bitmap, in pixels
             );

        [DllImportAttribute("gdi32.dll")]
        public static extern IntPtr SelectObject(
            IntPtr hdc,// handle to DC
            IntPtr hgdiobj   // handle to object
             );

        [DllImportAttribute("gdi32.dll")]
        public static extern bool DeleteObject(
            IntPtr hObject  // handle to graphic object
             );

        [DllImportAttribute("User32.dll")]
        public static extern bool PrintWindow(
              IntPtr hwnd,               // Window to copy
              IntPtr hdcBlt,             // HDC to print into
              int nFlags              // Optional flags
             );

        [DllImportAttribute("User32.dll")]
        public static extern int ReleaseDC(
              IntPtr hWnd,  // handle to window
              IntPtr hDC     // handle to DC
             );

        [DllImportAttribute("User32.dll")]
        public static extern bool ScreenToClient(
                IntPtr hWnd,        // handle to window
                ref LPPOINT lpPoint   // screen coordinates
             );

        [DllImportAttribute("User32.dll")]
        public static extern bool ClientToScreen(
                IntPtr hWnd,        // handle to window
                ref LPPOINT lpPoint   // screen coordinates
             );



    }
}
